package com.jedisCluster;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author wyx
 * @Date 2020/11/15 18:11
 */
public class JedisClusterCli {

//    private static JedisCluster jedisCluster;
//    static {
//        JedisPoolConfig config = new JedisPoolConfig();
//        config.setMaxIdle(100);
//        config.setMaxTotal(500);
//        config.setMinIdle(0);
//        config.setMaxWaitMillis(2000); // 设置2秒
//
//        config.setTestOnBorrow(true);
//        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
//        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7001));
//        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7002));
//        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7003));
//        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7004));
//        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7005));
//        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7006));
//
//        jedisCluster = new JedisCluster(jedisClusterNode, config);
//    }
    public static void main(String[] args) {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(100);
        config.setMaxTotal(500);
        config.setMinIdle(0);
        config.setMaxWaitMillis(2000); // 设置2秒

        config.setTestOnBorrow(true);
        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7001));
        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7002));
        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7003));
        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7004));
        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7005));
        jedisClusterNode.add(new HostAndPort("192.168.0.101", 7006));

        JedisCluster jedisCluster = new JedisCluster(jedisClusterNode, config);

        jedisCluster.set("name:007","詹姆斯邦德");
        System.out.println(jedisCluster.get("name:007"));
    }
}
